home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 042a / swagdef.zip / ENCRYPT.SWG < prev    next >
Text File  |  1993-05-28  |  35KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00014         FILE & ENCRYPTION ROUTINES                                        1      05-28-9313:40ALL                      SWAG SUPPORT TEAM        CHECKSUM.PAS             IMPORT              15          (*π> I finished Programming a Program in turbo pascal 7, and as some sharewareπ> Programs like RemoteAccess, Fastecho and more i want my Program to use aπ> KEY File to know if the Program is registered or not (i will supply a keyπ> For every sysop according to his bbs name and his name), any examples toπ> do such a Procedure?ππYou could do like I did in Terminate, make a big KeyFile around 4-8k andπincluded all kind of checksums calculated on crc-sums and the name etc.ππCalculate the Crc-sums in different ways, use always the GlobalChecksum to findπout if there has been no errors in the File. If error in the global checksum:ππ  SetFAttr(keyFile,Archive)      { if the File has been set to readonly }π  Erase(keyFile,archive)ππAsk user to install a new copy of the keyFile.ππThen somebody has changed it or an error has occured.ππThe next things is to use a different checksum For each release you make ofπyour Program, then people will get annoyed over waiting For a new pirate keyπand hopefully will send you some money.πThe cracker cannot calculate the checksum if you have no code in the Program,πbut he can crack the current version, but if you release a new version often,πpeople will get tired of that and pay. A checksum can be calculated in manyπdifferent ways like below:π*)πVarππ  KeyRec : Recordπ    Crc  : Array[1..100] of LongInt;π    Name : String[80];π    GlobalChecksum;π  end;ππVarπ  Sum : LongInt;π  X   : Word;ππbeginπ  Sum := 0;π  For x := 1 to Sizeof(KeyRec) Doπ    Inc(Sum, Mem[Seg(KeyRec) : Seg(KeyRec) + x]);π  { This will add all ascii values to crc, the cracker will prop. findπ    this out, but if you then : }π  Dec(Sum,3248967);π  { How should he find out if there is no code in your Program at the }π  { present version }πend.π                           2      05-28-9313:40ALL                      SWAG SUPPORT TEAM        COPYINC.PAS              IMPORT              21          { COPYINC.PAS    Author: Trevor J Carlsenπ                         PO Box 568π                         Port Hedland  6721π                         Western AustraliaπππSYNTAX:    copyinc Filenameππwhere Filename is the name of a Text File you wish to create that will be usedπas an include File in a Turbo Pascal Program.ππThis Program creates a Text File in the formatππ      Constπ        RegStr  ='This Program is an unregistered copy';π        CodeStr =π        #125#34#139#139#74#71#94#61#44#78#65#155#158#132#62#136#141#140#84+π        #34#155#63#38#46#89#84#93#57#153#51#83#112#72#36#138#93;π        keyval  = 1234567890;ππThe Text File that was used by COPYINC to create the above include File wouldπhave looked like thisππp:\prog\freeload.incπThis Program is an unregistered copyπRegStr  =πCodeStr =π1234567890ππHere is another example.  This was the include File -ππ      Constπ        ChkStr     : String ='This Program is registered to';π        CodeChkStr : String =π        #32#153#90#34#133#140#42#129#150#50#81#36#83#36#133#154#52#76#75+π        #129#45#93#77#44#83#149#157#71#95#225;π        keyval  = 1234567890;ππand the Text File used by COPYINC -ππp:\prog\registed.incπThis Program is registered to πChkStr     : String =πCodeChkStr : String =π1234567890πππThe Text File must always consist of five lines that areπ 1.  The name of the include File to be created.π 2.  The plain Text.π 3.  The name of the plain Text Constant along With its syntax.π 4.  The name and syntax of the coded Text Constant.π 5.  A key value.  Any number in the LongInt range is valid.πππ}ππUsesπ  endecode;  { my encryption Unit }ππConstπ  hash   = '#';πVarπ  f      : Text;π  params : Text;π  keyval : LongInt;π  notice,π  fname,π  CodeStr,π  CodeVar,π  PlainVar: String;π  x      : Word;ππbeginπ  assign(params,ParamStr(1));π  reset(params);π  readln(params,fname);π  readln(params,notice);π  readln(params,PlainVar);π  readln(params,CodeVar);π  readln(params,keyval);π  CodeStr := EncryptStr(keyval,notice);π  notice := '  '+ PlainVar + #39 + notice + #39#59;π  assign(f,fname);π  reWrite(f);π  Writeln(f,'Const');π  Writeln(f,notice);π  Writeln(f,'  ',CodeVar);π  Write(f,'  ');π  For x := 1 to length(CodeStr) do beginπ    if x mod 20 = 0 then beginπ      Writeln(f,'+');π      Write(f,'  ');π    end;π    Write(f,'#',ord(CodeStr[x]));π  end;π  Writeln(f,';');π  Writeln(f,'  keyval  = ',keyval,#59);π  Writeln(f);π  close(f);πend.ππ                                                                                                                             3      05-28-9313:40ALL                      SWAG SUPPORT TEAM        ENCRYPT.PAS              IMPORT              65          {$A+,B-,D-,E+,F-,G+,I+,L-,N-,O-,R-,S-,V-,X+}π{$M 4048,0,131040}πProgram encrypt;ππ{ Author Trevor J Carlsen - released into the public domain 1992         }π{        PO Box 568                                                      }π{        Port Hedland                                                    }π{        Western Australia 6721                                          }π{        Voice +61 91 73 2026  Data +61 91 73  2569                      }π{        FidoNet 3:690/644                                               }ππ{ Syntax: encrypt /p=PassWord /k=KeyFile /f=File                         }π{ Example -                                                              }π{         encrypt /p=billbloggs /k=c:\command.com /f=p:\prog\anyFile.pas }ππ{         PassWord can be any alpha-numeric sequence of AT LEAST four    }π{         Characters.                                                    }ππ{         KeyFile is the full path of any File on the system that this   }π{         Program runs on.  This File, preferably a large one, must not  }π{         be subject to changes.  This is critical as it is used as a    }π{         pseudo "one time pad" style key and the slightest change will  }π{         render decryption invalid.                                     }ππ{         File is the full path of the File to be encrypted or decrypted.}ππ{ notes:  Running Encrypt a second time With exactly the same parameters }π{         decrypts an encrypted File.  For total security the keyFile    }π{         can be stored separately on a floppy.  Without this keyFile or }π{         knowledge of its contents it is IMPOSSIBLE to decrypt the      }π{         encrypted File.                                                }ππ{         Parameters are Case insensitive and may be in any order and    }π{         may not contain any Dos separator Characters.                  }ππConstπ  BufferSize   = 65520;π  Renamed      : Boolean = False;ππTypeπ  buffer_      = Array[0..BufferSize - 1] of Byte;π  buffptr      = ^buffer_;π  str80        = String[80];ππVarπ  OldExitProc  : Pointer;π  KeyFile,π  OldFile,π  NewFile      : File;π  KeyBuffer,π  Buffer       : buffptr;π  KeyFileSize,π  EncFileSize  : LongInt;π  PassWord,π  KFName,π  FFName       : str80;ππProcedure Hash(p : Pointer; numb : Byte; Var result: LongInt);π  { When originally called numb must be equal to sizeof    }π  { whatever p is pointing at.  if that is a String numb   }π  { should be equal to length(the_String) and p should be  }        π  { ptr(seg(the_String),ofs(the_String)+1)                 }π  Varπ    temp,π    w    : LongInt;π    x    : Byte;ππ  beginπ    temp := LongInt(p^);  RandSeed := temp;π    For x := 0 to (numb - 4) do beginπ      w := random(maxint) * random(maxint) * random(maxint);π      temp := ((temp shr random(16)) shl random(16)) +π                w + MemL[seg(p^):ofs(p^)+x];π    end;π    result := result xor temp;π  end;  { Hash }ππProcedure NewExitProc; Far;π  { Does the "housekeeping" necessary on Program termination }π  Var code : Integer;π  beginπ    ExitProc := OldExitProc;  { Reset Exit Procedure Pointer to original }π    Case ExitCode ofπ    0: Writeln('Successfully encrypted or decrypted ',FFName);π    1: beginπ         Writeln('This Program requires 3 parameters -');π         Writeln('  /pPassWord');π         Writeln('  /kKeyFile (full path and name)');π         Write  ('  /fFile (The full path and name of the File');π         Writeln(' to be processed)');π         Writeln;π         Write  ('These parameters can be in any order, are Case,');π         Writeln(' insensitive, and may not contain any spaces.');π       end;π    2: Writeln('Could not find key File');π    3: Writeln('Could not rename and/or open original File');π    4: Writeln('Could not create encrypted File');π    5: Writeln('I/O error during processing - could not Complete');π    6: Writeln('Insufficient memory available');π    7: beginπ         Writeln('Key  File is too small - aborted');π         Writeln;π         Writeln(' Key File must be at least as large as the buffer size ');π         Write  (' or the size of the File to be encrypted, whatever is the');π         Writeln(' smaller.');π       end;π    8: Writeln('PassWord must consist of at least 4 Characters');π    else { any other error }π      Writeln('Aborted With error ',ExitCode);π    end; { Case }π    if Renamed and (ExitCode <> 0) thenπ      Writeln(#7'WARNinG: original File''s name is now TEMP.$$$');π    {$I-}π    close(KeyFile); Code := Ioresult;π    close(NewFile); Code := Ioresult;π    close(OldFile); Code := Ioresult;π    if ExitCode = 0 thenπ      Erase(OldFile); Code := Ioresult;π    {$I+}π  end; { NewExitProc }πππFunction Str2UpCase(Var S: String): String;π  { Converts a String S to upper Case.  Valid For English. }π  Varπ    x : Byte;π  beginπ    Str2UpCase[0] := S[0];π    For x := 1 to length(S) doπ      Str2UpCase[x] := UpCase(S[x]);π  end; { Str2UpCase }ππProcedure Initialise;π  Varπ    CommandLine : String;π    FPos,FLen,π    KPos,KLen,π    PPos,PLen   : Byte;ππ  Procedure  AllocateMemory(Var p: buffptr; size: LongInt);π    beginπ      if size < BufferSize then beginπ        if MaxAvail < size then halt(6);π        GetMem(p,size);π      endπ      else beginπ        if MaxAvail < BufferSize then halt(6);π        new(p);π      end;π    end; { AllocateMemory }ππ  beginπ    FillChar(OldExitProc,404,0);       { Initialise all global Variables }π    FillChar(PassWord,243,32);π    ExitProc    := @NewExitProc;             { Set up new Exit Procedure }π    if ParamCount <> 3 then halt(1);π    CommandLine := String(ptr(PrefixSeg,$80)^)+' '; { Add trailing space }π    CommandLine := Str2UpCase(CommandLine);      { Convert to upper Case }π    PPos        := pos('/P=',CommandLine);     { Find passWord parameter }π    KPos        := pos('/K=',CommandLine);      { Find keyFile parameter }π    FPos        := pos('/F=',CommandLine); { Find Filename For encryption}π    if (PPos = 0) or (KPos = 0) or (FPos = 0) then Halt(1);π    FFName      := copy(CommandLine,FPos+3,80);π    FFName[0]   := chr(pos(' ',FFName)-1);       { Correct String length }π    KFName      := copy(CommandLine,KPos+3,80);π    KFName[0]   := chr(pos(' ',KFName)-1);π    PassWord    := copy(CommandLine,PPos+3,80);π    PassWord[0] := chr(pos(' ',PassWord)-1);π    if length(PassWord) < 4 then halt(8);π    { Create a random seed value based on the passWord }π    Hash(ptr(seg(PassWord),ofs(PassWord)+1),length(PassWord),RandSeed);π    assign(OldFile,FFName);π    {$I-}π    rename(OldFile,'TEMP.$$$');π    if Ioresult <> 0 thenπ      halt(3)π    elseπ      renamed := True;π    assign(OldFile,'TEMP.$$$');π    reset(OldFile,1);π    if Ioresult <> 0 then halt(3);π    assign(NewFile,FFName);π    reWrite(NewFile,1);π    if Ioresult <> 0 then halt(4);π    assign(KeyFile,KFName);π    reset(KeyFile,1);π    if Ioresult <> 0 then halt(2);π    EncFileSize := FileSize(OldFile);π    KeyFileSize := FileSize(KeyFile);π    if KeyFileSize > EncFileSize thenπ      KeyFileSize := EncFileSize;π    if Ioresult <> 0 then halt(5);π    {$I+}π    if (KeyFileSize < BufferSize) and (KeyFileSize < EncFileSize) thenπ      halt(7);π    AllocateMemory(buffer,EncFileSize);π    AllocateMemory(KeyBuffer,KeyFileSize);π  end; { Initialise }ππProcedure Main;π  Varπ    BytesRead : Word;π    finished  : Boolean;ππ  Procedure CodeBuffer(number: Word);π    { This is the actual encryption/decryption engine }π    Var x : Word;π    beginπ      For x := 0 to number - 1 doπ        buffer^[x] := buffer^[x] xor KeyBuffer^[x] xor Random(256);π    end; { CodeBuffer }ππ  beginπ    {$I-}π    finished := False;π    Repeatπ      BlockRead(OldFile,buffer^,BufferSize,BytesRead);π      if Ioresult <> 0 then halt(5);π      if (FilePos(KeyFile) + BytesRead) > KeyFileSize thenπ        seek(KeyFile,0);π      BlockRead(KeyFile,KeyBuffer^,BytesRead,BytesRead);π      if Ioresult <> 0 then halt(5);π      CodeBuffer(BytesRead);π      finished := BytesRead < BufferSize;π      BlockWrite(NewFile,buffer^,BytesRead);π    Until finished;π  end;  { Main }ππbeginπ  Initialise;π  Main;πend.π                                                                     4      05-28-9313:40ALL                      SWAG SUPPORT TEAM        ENCRYPT1.PAS             IMPORT              6           Function EncryptDecrypt(S : String : K : String) : String;πVarπ  I,Q : Integer;π  O   : String[255];πbeginπ  Q := 1;π  O := "";π  For I := 1 to Length(S) Doπ    beginπ      O := O + Chr(Ord(S[I]) Xor Ord(K[Q]));π      Inc(Q); If Q > Length(K) Then Q := 1;π    end;π  EncryptDecrypt := O;πend;ππA couple of thoughts on this.ππ1. If K is short then the decryption is very easy.π2. The routine would be VERY slow as it is using String concatenation.  Itπ   would be MUCH faster if the O := "" line was changed to O[0] := S[0] andπ   the O := O + ... line was replaced With -π   O[I] := ...ππTeeCeeπ                                             5      05-28-9313:40ALL                      SWAG SUPPORT TEAM        ENCRYPT2.PAS             IMPORT              10          {The following very simple routine will encrypt and decrypt a Text File a lineπat a time.  The CR/LF is left unencrypted and the algorithm ensures that noπencrypted Character can be < asciiz 127 *provided that* the Text For encryptingπhas no hi-bit Characters.ππObviously this is just a skeleten example (untested) With no error checking butπit should demonstrate what you need to do. After encrypting Text just reverseπthe parameters and run the Program again to decrypt the encrypted Text.π}πProgram encrypt_Text;ππVarπ  inText,π  outText  : Text;π  st       : String;ππFunction ConvertTxt(s: String): String;π  Var x : Byte;π  beginπ    ConvertTxt[0] := s[0];π    For x := 1 to length(s) doπ      ConvertTxt[x] := chr(ord(s[x]) xor (Random(128) or 128));π  end;  { ConvertTxt }ππbeginπ  RandSeed  := 1234567;{ set to whatever value you wish - this is your "key" }π  assign(inText,ParamStr(1));π  reset(inText);π  assign(outText,ParamStr(2));π  reWrite(outText);π  While not eof(inText) do beginπ    readln(inText,st);π    Writeln(outText,ConvertTxt(st));π  end;π  close(inText);π  close(outText);πend.π                                               6      05-28-9313:40ALL                      SWAG SUPPORT TEAM        ENCRYPT3.PAS             IMPORT              12          { JL> I'm writing a Program to set and test passWords. I imagine you saw it inπ JL> PASCAL echo. Well, I want to know if there is an easier way to encrypt aπ JL> File then to assign a different Character to each letter. This is theπ JL> only way that I can think of to do this.ππ JL> 'A':= '^';π JL> 'B':= 'q';ππWhat you suggest isn't so much encryption as it is a substitution cypher.  Theπfollowing is more of an *encryption*:π}ππFunction Crypt(S : String) : String;π(* xor can be used to *toggle* values.  In this Case it is toggling  *)π(* Character of the String based on its postion in the String.  This *)π(* ensures that the mask is always known For the pupose of decoding. *)π  Varπ    i : Byte;π  beginπ    For i := 1 to Length(S) Doπ      S[i] := Char(ord(S[i]) xor i);π    Crypt := S;π  end;ππVarπ  TestS : String;π  TestMask : Byte;ππbeginπ  TestS := 'This is a test 1234567890 !@$%';π  Write('original: ');π  Writeln(TestS);ππ  TestS := Crypt(TestS);π  Write('Encrypt : ');π  Writeln(TestS);ππ  TestS := Crypt(TestS);π  Write('Decrypt : ');π  Writeln(TestS);πend.ππ{Please note that this was a quickie and not fully tested and thereForeπcannot be guaranteed to be perfect.  <grin>  But it ought to give you aπslightly different perspective and help you see alternate approaches toπthe problem.π}π                                                                                                  7      05-28-9313:40ALL                      SWAG SUPPORT TEAM        ENCRYPT4.PAS             IMPORT              12          { JC> I was wondering what Format you Programmers out there use to makeπ JC> registration codes.  I was fooling around With a letter standing Forπ JC> another letter but thats too simple.  How can I go about writingπ JC> bullet proof (or at least bullet resistant)  registration codes.  BTW,π JC> this is not an over the modem Type Program.  if you understand whatπ JC> I'm TRYinG to say, I wopuld RealLY appreciate a response.  Thanks aπ JC> lot!!!π}πππProgram RegCode;ππUses Crt;ππVarπ  ch : Char;π  Name : String;ππFunction MakeRegCode(S:String): LongInt;ππVarπ I: LongInt;π B: Byte;ππbeginπ I:=0;   { Could make this something else if you want it more random looking }π For B:=1 to Length(S)π  Do I:=I+ord(S[B]); { Could make it ord(S[B]+SomeValue) to make it moreπ                interesting }π MakeRegCode:=I;πend;ππbeginππ Writeln;π Writeln;π Write('Enter SysOp Name : ');π Readln(Name);π Writeln;π Writeln('The resultant code was ',MakeRegCode(Name));π Writeln;π ch:=ReadKey;ππend.πππ{You can also add a BBS Name or a City or anything else you want. just keep onπadding it to the I Var in the MakeRegCode proc.  to check to see if a reg codeπis valid, just Compare the registration code he already has (in a cfg Fileπcomewhere I assume) With the one generated this part of code.  if they match,πthen is is a good code... if not... then he didn't register.π}π                                          8      05-28-9313:40ALL                      SWAG SUPPORT TEAM        ENDECODE.PAS             IMPORT              31          Unit endecode;π { Simple encryption/decryption routines.                  }ππInterfaceππTypeπ  stArray = Array[0..255] of Byte;ππFunction Key(Var s): LongInt;πFunction EncryptStr(key : LongInt; s: String): String;πFunction DecryptStr(key : LongInt; s: String): String;ππImplementationππFunction MakeCodeStr(key : LongInt; Var s): String;π  {--------------------------------------------------------}π  { Creates a "randomly" Constructed String of a similar   }π  { length as the String which is to be encrypted. A       }π  { LongInt key is used to permit "passWord" Type          }π  { encryption. This key may be passed as a literal or     }π  { some passWord used to calculate it. Using this key,    }π  { the last Character of the String to be encrypted and   }π  { the length of the String, a "code String" is produced. }π  { This code String is then xord With the original String }π  { to produce the encrypted String. The last Character    }π  { however must be treated differently so that it can be  }π  { easily decoded in order to reproduce the coded String  }π  { used For decoding. This is done by xoring it With the  }π  { length of the String. to decrypt a String the last     }π  { Character must be decoded first and then the key coded }π  { String produced in order to decrypt each Character.    }π  {--------------------------------------------------------}ππ  Varπ    x   : Word;π    len : Byte Absolute s;π    st  : Array[0..255] of Byte Absolute s;ππ  beginπ    RandSeed := (key * len) div st[len];π    {This ensures that no two code Strings will be similar UNLESS they areπ     of identical length, have identical last Characters and the sameπ     key is used.}π    MakeCodeStr[0] := chr(len);π    For x := 1 to len doπ      MakeCodeStr[x] := chr(32 + Random(95));π      {Keeping the Character between 32 and 127 ensures that the high bitπ       is never set on the original encrypted Character and thereFore allowsπ       this to be used as flag to indicate that the coded Char was < #32.π       This will then permit the encrypted String to be printed without fearπ       of having embedded control codes play havoc With the Printer.}π  end;ππFunction Key(Var s): LongInt;π  { Creates a key For seeding the random number generator. st can be aπ    passWord }π  Varπ    x     : Byte;π    temp  : LongInt;π    c     : Array[1..64] of LongInt Absolute s;π    len   : Byte Absolute s;π  beginπ    temp  := 0;π    For x := 1 to len div 4 doπ      temp := temp xor c[x];π    Key := Abs(temp);π  end;ππFunction EncryptStr(key : LongInt; s: String): String;π  Varπ    cnt,x          : Byte;π    len            : Byte Absolute s;π    st             : Array[0..255] of Byte Absolute s;π    CodeStr        : stArray;π    temp           : String Absolute CodeStr;π  beginπ    temp           := MakeCodeStr(key,st);π    EncryptStr[0]  := chr(len);π    EncryptStr[len]:= chr(st[len]);π    For x := 1 to len-1 do beginπ      cnt := st[x] xor CodeStr[x];π      inc(cnt,128 * ord(cnt < 32));π      EncryptStr[x]:= chr(cnt);π    end;  { For }π    cnt := st[len] xor (len and 127);π    inc(cnt,128 * ord(cnt < 32));π    EncryptStr[len]:= chr(cnt);π  end;ππFunction DecryptStr(key : LongInt; s: String): String;π  Varπ    cnt,x        : Byte;π    st           : stArray Absolute s;π    len          : Byte Absolute s;π    CodeStr      : stArray;π    temp         : String Absolute CodeStr;π    ch           : Char;π  beginπ    cnt          := st[len] and 127;π    st[len]      := cnt xor len;π    temp         := MakeCodeStr(key,st);π    DecryptStr[0]:= chr(len);π    DecryptStr[len]:= chr(st[len]);π    For x := 1 to len-1 do beginπ      cnt        := st[x];π      dec(cnt,128 * ord(st[x] > 127));π      DecryptStr[x] := chr(cnt xor CodeStr[x]);π    end;  { For }π  end;ππend.π                                                           9      05-28-9313:40ALL                      SWAG SUPPORT TEAM        HASH.PAS                 IMPORT              28          Unit Hash;ππ{***************************************************************************π *                                                                         *π *                     Copyright 1989 Trevor J Carlsen                     *π *                           All rights reserved                           *π *                   Rovert Software Consulting Services                   *π *                                PO Box 568                               *π *                   Port Hedland Western Australia 6721                   *π *                 Telephone  (091) 732026 or (091) 732569                 *π *                                                                         *π ***************************************************************************}ππInterfaceππUses Strings,π     sundry;ππFunction hashcode(st : String; Var nwd : Word): Word;ππImplementationππFunction MakeCodeStr(key : LongInt; st : String): String;π  Varπ    x   : Word;π    len : Byte Absolute st;π  beginπ    RandSeed := (key * len) div ord(st[len]);π    MakeCodeStr[0] := st[0];π    For x := 1 to len doπ      MakeCodeStr[x] := chr(Random(255));π  end;ππFunction Key(st: String): LongInt;π  Varπ    len    : Byte Absolute st;π    x,y    : Byte;π    temp   : LongInt;π    tempst : Array[0..3] of Byte;ππ  Procedure makekey(Var k; Var s : LongInt);π    Var t : LongInt Absolute k;π      rec : Recordπ              Case Byte ofπ               1 :(b : LongInt; c : Word);π               2 :(d : Word ; e : LongInt);π               3 :(r : Real);π              end;π    beginπ      RandSeed := t;π      rec.r := random;π      s := s xor rec.b xor rec.e;π    end;ππ  beginπ    temp := 0;π    For x := 1 to len-3 do beginπ      For y := 0 to 3 doπ        tempst[y] := Byte(st[x + y]);π      makekey(tempst,temp);π    end;π    Key := temp;π  end;ππFunction EncryptStr(key : LongInt; st : String): String;π  Varπ    len          : Byte Absolute st;π    cnt,x        : Byte;π    temp,CodeStr : String;π  beginπ    CodeStr := MakeCodeStr(key,st);π    temp[0] := st[0];π    temp[len] := st[len];π    For x := 1 to len-1 do beginπ      cnt := ord(st[x]) xor ord(CodeStr[x]);π      temp[x] := chr(cnt);π      end;π    cnt := ord(st[len]) xor len;π    temp[len] := chr(cnt);π    EncryptStr := temp;π  end;ππFunction hashcode(st : String; Var nwd : Word): Word;π  Var k   : LongInt;π      len : Byte Absolute st;π      s   : String;π  beginπ    k := key(st) * nwd;π    st := StUpCase(st);π    s := CompressStr(st);π    move(s[1],nwd,2);π    if len < 4 then st := st + '!@#$';π    {-Force String to a minimum length}π    st := EncryptStr(k,st);π    st := EncryptStr(Key(st),st);π    hashcode := key(st) shr 16;π  end;  {hash}ππend.πππ{π> Procedure Hash(p : Pointer; numb : Byte; Var result: LongInt);ππ> ... Is this the way that you were referring to storing passWords?π> if so could further explain the usage of this Procedure? Thanx!!ππYes, but I take issue With the Word "store".  Storing the passWord hash is notπstoring the passWord as the passWord cannot be determined by examining the hashπ- even if the hash algorithm is known.ππto use the Procedure -ππWhen the passWord is first created, calculate its hash and store that valueπsomewhere - either in a File or in the exe.ππthen when the passWord is used just -ππ  Hash(@passWord,length(passWord),EnteredHash);π  if PwdHash = EnteredHash then PassWord_Entered_is_Correct.π}                                    10     05-28-9313:40ALL                      SWAG SUPPORT TEAM        PASCASE.REP              IMPORT              13          CHECKSUM.PASπ             Program : 8π           Procedure : 1π             LongInt : 2π                Word : 1π                File : 7π                For  : 3πMade 22 changes to CHECKSUM.PAS in 0.88 seconds.ππCOPYINC.PASπ             Program : 6π                Uses : 1π                Unit : 1π               Const : 6π                 Var : 1π              String : 5π             LongInt : 2π                Word : 1π                File : 11π                Text : 10π                For  : 1πMade 45 changes to COPYINC.PAS in 1.04 seconds.ππENCRYPT.PASπMade 0 changes to ENCRYPT.PAS in 1.87 seconds.ππENCRYPT1.PASπ              String : 1πMade 1 changes to ENCRYPT1.PAS in 0.71 seconds.ππENCRYPT2.PASπMade 0 changes to ENCRYPT2.PAS in 0.77 seconds.ππENCRYPT3.PASπMade 0 changes to ENCRYPT3.PAS in 0.82 seconds.ππENCRYPT4.PASπMade 0 changes to ENCRYPT4.PAS in 0.88 seconds.ππENDECODE.PASπMade 0 changes to ENDECODE.PAS in 1.15 seconds.ππHASH.PASπMade 0 changes to HASH.PAS in 1.21 seconds.ππPASSWORD.PASπMade 0 changes to PASSWORD.PAS in 0.93 seconds.ππPATCHEXE.PASπMade 0 changes to PATCHEXE.PAS in 0.93 seconds.ππXORCODE.PASπ                xor  : 2πMade 2 changes to XORCODE.PAS in 0.88 seconds.πππFiles Processed  :           12πBytes Processed  :       30,724πTotal Scans      :        1,908πBytes Scanned    :   58,621,392πTotal Changes    :           70πTotal Time       :        12.31 SecondsπBytes Per Second :    4,762,988π                                                                                              11     05-28-9313:40ALL                      SWAG SUPPORT TEAM        PASSWORD.PAS             IMPORT              20          { JL>Help me guys. I'm learning about reading from a File. I am creating aπ JL>Program that will let you set passWord and test a passWord.ππ JL>Also how do you make the screen print a Character like .... instead of aπ JL>Word.  So when you enter in a passWord like in BBS it won't show it?ππ------------------------------------X----------------------------------------π}ππProgram TestPW;ππ{πProgrammer      : Chet Kress (FidoNet 1:283/120.4)πBeen Tested?    : YES, this has been tested.  It works!πoriginal Date   : 01/01/93πCurrent Version : v1.0πLanguage        : Turbo Pascal v7.0πPurpose         : Make a passWord routineπ}ππUses Crt;ππProcedure TestPassWord;ππConstπ  DataFile = 'PW.DAT'; {The name of the data File containing the passWord}π  {Just have one line in the PW.DAT File, and use that as the passWord}ππVarπ  PassWordFile : Text; {The name assigned to the data File}π  PassCH : Char; {A Character that the user has entered}π  TempPassWord : String; {The temporary passWord from the user}π  ThePW : String; {The Real passWord from the data File}ππbegin {TestPassWord}π  Assign (PassWordFile, DataFile);π  Reset (PassWordFile);π  ClrScr;π  TempPassWord := '';π  Write ('Enter passWord: ');π{π  I replaced the Readln With this Repeat..Until loop so you can see theπ  "periods" instead of the Characters (like you wanted).  This is a simpleπ  routine, but it should suffice For what you want it to do.  It has someπ  error checking and backspacing is available too.π}π  Repeatπ    PassCH :=  ReadKey;π    if (PassCH = #8) and (Length(TempPassWord) > 0) thenπ      beginπ        Delete (TempPassWord, Length(TempPassWord), 1);π        GotoXY (WhereX-1, WhereY);π        Write (' ');π        GotoXY (WhereX-1, WhereY);π      end;π    if (PassCH >= #32) and (PassCH <= #255) thenπ      beginπ        TempPassWord := TempPassWord + PassCH;π        Write ('.');π      end;π  Until (PassCH = #13);π  Writeln;π  Readln (PassWordFile, ThePW);        { <-- You Forgot to add this line }π  if TempPassWord = ThePW thenπ    beginπ      Writeln ('You have received access.');π      Writeln ('Loading Program.');π      { Do whatever else you want to here }π    endπ  elseπ    beginπ      Writeln ('Wrong PassWord.');π    end;π  Close (PassWordFile);πend; {TestPassWord}ππbegin {Main}π  TestPassWord;πend. {Main}ππ                                                                                                                        12     05-28-9313:40ALL                      SWAG SUPPORT TEAM        PATCHEXE.PAS             IMPORT              20          { PD> This looks like something I would like to add to my Programs.  Myπ PD> question is, how do you modify the .exe from the Program.  I can do theπ PD> encryption but don't know how to store the encrypted passWords in theπ PD> Program's own .exe.  Any help would be appreciated.π}ππProcedure PatchExeFile(ItemAddr:Pointer;itemsize:LongInt);πVarπ  FiletoPatch : File;π  HeaderSize  : Word;π  seeksize    : LongInt;π  offset      : Word;π  LDseg       : LongInt;π  ch          : Char;ππbeginπ  assign(FiletoPatch, paramstr(0));π  reset(FiletoPatch, 1);π  seek(FiletoPatch, 8);π  blockread(Filetopatch, headersize, sizeof(headersize));π  offset := ofs(itemAddr^);π  Ldseg := LongInt(Dseg);π  seeksize := 16 * (LDseg - PrefixSeg + HeaderSize) + offset - 256π    seek(Filetopatch, seeksize);π  blockWrite(Filetopatch, ItemAddr^, ItemSize);π  close(Filetopatch);πend;ππ{Call it this way:π}πPatchExeFile(Addr(passWords), sizeof(passWords));ππ{note that For this to work, passWords must be a TypeD ConstANT.πSo you declare it this way:π}π  PassWords : PassWord_Array =π  (π    (PassWord : #247#154#189#209#18#104#143#29; Protected : False),π    .π    .π    .π    (PassWord : #247#154#189#209#18#104#143#29; Protected : False)π  );ππ{  PassWord_Array is declard as an Array of PassWord_Record;ππ    The above declaration is from my Crypto.inC. I have a Crypto.PASπProgram that generates this File from my Make File so that on eachπCompile the encryption is changed and the Array of passWords is storedπwith valid encrypted passWords. I used #<AsciiValue> because theπencryption can generate values from Ascii 0 to Ascii 255 and some ofπthose cause troubles in Strings Constants using "'" as delimeters.ππ    As long as you use:ππConst <ConstName> : <ConstType> = <ConstantValue>;ππ    You will be sure PatchExe can find it's correct adress in the EXE.πFrom there on you can read it in your TP Program as usual and store itπusing the call to PatchExe I gave up there.ππ    BTW, do as I do and generate a new random encryption key on eachπrun, Re-encrypting everything and writting it back to the exe. Thisπdrives Hackers mad when they try to decypher your encrypted passWords.ππOne last note:π    The above PatchExe was written when I used TP 6.0. I haven't checkedπ    yet if TP 7.0 Uses different mapping of his EXe and it will mostπ    probably not work on a Protected-mode Compiled EXE.π}π                                               13     05-28-9313:40ALL                      SWAG SUPPORT TEAM        SOUNDEX.PAS              IMPORT              12          {πREYNIR STEFANSSONππSomebody was saying something about Soundex hashing. Here is myπImplementation of that:π}ππUnit Soundex;ππInterfaceππTypeπ  Sdx4 = String[4];ππFunction SoundexOf(WorkStr : String) : Sdx4;ππImplementationππVarπ  Group : Array[0..6] of String[8];ππFunction ValidityOf(Letter : Char) : Char;πVarπ  Valu, j : Integer;π  Chs     : String[8];πbeginπ  For Valu := 0 to 6 DOπ  beginπ    Chs := Group[Valu];π    For j := 1 to Length(Chs) DOπ    beginπ      if UpCase(Letter) = Chs[j] thenπ        ValidityOf := Chr(48+Valu);π    end;π  end;πend;ππFunction SoundexOf(WorkStr : String) : Sdx4;πVarπ  Sndex : Sdx4;π  Oval,π  Valu  : Char;π  i     : Integer;πbeginπ  Sndex := Copy(WorkStr, 1, 1);π  Oval  := ValidityOf(WorkStr[1]);π  For i := 2 to Length(WorkStr) DOπ  beginπ    Valu := ValidityOf(WorkStr[i]);π    if (Valu <> '0') and (Valu <> Oval) thenπ      Sndex := Sndex + Valu;π    Oval := Valu;π  end;π  Sndex := Sndex + '000';π  SoundexOf := Sndex;πend;ππbeginπ  Group[0] := 'AEHIOUWY';π  Group[1] := 'BFPV';π  Group[2] := 'CGJKQSXZ';π  Group[3] := 'DT';π  Group[4] := 'L';π  Group[5] := 'MN';π  Group[6] := 'R';πend.ππ{πA Soundex-String looks like: `G032', one letter and three numbers.πDonald Knuth wrote about Soundexing in his _Art of Computer Programming_πseries. I got my information out of Personal ComputerWorld (PCW), which inπturn got it from Knuth.π}π                             14     05-28-9313:40ALL                      SWAG SUPPORT TEAM        XORCODE.PAS              IMPORT              11          {π│ Is if possible For you to post a sample code on how to use xor toπ│ encrypt a File???   I'm shifting ORD value around to do excryptionsπ│ and I think your method is better..  So I would like to learn it..ππSure, here's a simple example that reads a user-entered line andπencrypts it using the xor method.  By XOR-ing it again the line isπdecrypted.  This won't keep NSA fooled For more than a few seconds, butπso long as you keep the passWord hidden it should suffice.π}πππProgram Sample;ππUsesπ  Crt;ππConstπ  PassWord : Array[1..8] of Char = 'Sha Zamm';ππVarπ  PassBits : Array[1..8] of Byte Absolute PassWord;π  ALine    : String[80];π  LineBits : Array[0..80] of Byte Absolute ALine;π  I, J, K  : Integer;πbeginπ  WriteLn('Enter a line of Text to encrypt:');π  ReadLn(ALine);π  J := 0;π  For I := 1 to Length(ALine) Doπ  beginπ    Inc(J);π    If J > 8 Thenπ      J := 1;π    LineBits[I] := LineBits[I] xor PassBits[J];π  end;π  WriteLn('Encrypted:  ',ALine);π  J := 0;π  For I := 1 to Length(ALine) Doπ  beginπ    Inc(J);π    If J > 8 Thenπ      J := 1;π    LineBits[I] := LineBits[I] xor PassBits[J];π  end;π  WriteLn('Decrypted:  ',ALine);πend.π